package com.cloud2022.sharding.config.WeChatPayRecordRule;

import com.cloud2022.sharding.config.CodeShardingMap;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.complex.ComplexKeysShardingValue;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author: create by God of SJF
 * @version: v1.0
 * @description: com.cloud2022.sharding.config
 * @date:2022/2/11
 */
public class WeChatPayRecordRule implements ComplexKeysShardingAlgorithm<Integer> {


    @Override
    public Collection<String> doSharding(Collection<String> collection, ComplexKeysShardingValue<Integer> complexKeysShardingValue) {
        Map<String, Collection<Integer>> columnNameAndShardingValuesMap = complexKeysShardingValue.getColumnNameAndShardingValuesMap();
        List<Integer> queryList = (List<Integer>) columnNameAndShardingValuesMap.get("_year");
        Integer query = queryList.get(0);
        String logicTableName = complexKeysShardingValue.getLogicTableName();
        List<String> tables = new ArrayList<>(1);
        tables.add("_"+String.valueOf(query-2000)+logicTableName);
        return tables;
    }

}
